# -*- coding: utf-8 -*-
#ref: https://github.com/NicolasHug/Surprise
#install: pip --proxy http://109.105.1.52:8080 install scikit-surprise

from surprise import SVD
from surprise import Dataset, Reader
from surprise import evaluate, print_perf
import os


if __name__ == "__main__":
    os.chdir("..")
    # Load the movielens-100k dataset (download it if needed),
    # and split it into 3 folds for cross-validation.
    #data = Dataset.load_builtin('ml-100k')

    # path to dataset file
    file_path = os.path.expanduser('output/ml-100k/u.data')

    # As we're loading a custom dataset, we need to define a reader. In the
    # movielens-100k dataset, each line has the following format:
    # 'user item rating timestamp', separated by '\t' characters.
    reader = Reader(line_format='user item rating timestamp', sep='\t')

    data = Dataset.load_from_file(file_path, reader=reader)

    data.split(n_folds=3)

    # We'll use the famous SVD algorithm.
    algo = SVD()

    # Evaluate performances of our algorithm on the dataset.
    perf = evaluate(algo, data, measures=['RMSE', 'MAE'])

    print_perf(perf)